script_enemy_main{

let angle=0;
let soundtime=0;

let shot1=0;
let bullet1=[];
let timer1=[];

let character="SayuriMai";
let cutin=character;
let dispelled=0;
let spellcards=1;
if(GetCommonData("Difficulty")>=3){ spellcards=2; }
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let frame=0; let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshots6=("script\SoundEffects\shots6.wav");
let SEmagics5=("script\SoundEffects\magics5.wav");

#include_function "script/Functions/HealthBarLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsSayuriMai1.txt");

	LoadGraphic("\script\Images\CharacterSprites\Sayuri.png");
	LoadGraphic("\script\Images\CharacterSprites\Mai.png");

	LoadSE("script\SoundEffects\shots6.wav");
	LoadSE("script\SoundEffects\magics5.wav");

	SetLife(200);
	SetTimer(30);
	SetInvincibility(120);
	SetDamageRate(10,10); 
	SetEnemyMarker(false);
	MagicCircle(false);
	SetX(cx);
	SetY(miny-1000);
	
	SetCommonData("UseSpell1",0);
	SetCommonData("UseSpell2",0);
}
	
@MainLoop{

SetCollisionA(GetCommonData("Boss1X"),GetCommonData("Boss1Y"),16);
SetCollisionA(GetCommonData("Boss2X"),GetCommonData("Boss2Y"),16);
SetCollisionB(GetCommonData("Boss1X"),GetCommonData("Boss1Y"),16);
SetCollisionB(GetCommonData("Boss2X"),GetCommonData("Boss2Y"),16);
SetShotAutoDeleteClip(32,32,32,32);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=3; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

HealthBar();


if(time==0){
CreateEnemyFromFile(GetCurrentScriptDirectory~"Sayuri-Mai - Nonspell 3 - Sayuri.txt",GetCommonData("Boss1X"),GetCommonData("Boss1Y"),0,0,0);
CreateEnemyFromFile(GetCurrentScriptDirectory~"Sayuri-Mai - Nonspell 3 - Mai.txt",GetCommonData("Boss2X"),GetCommonData("Boss2Y"),0,0,0);
}

let boss1x=GetCommonData("Boss1X");
let boss1y=GetCommonData("Boss1Y");
let boss2x=GetCommonData("Boss2X");
let boss2y=GetCommonData("Boss2Y");

if(GetCommonData("Difficulty")==1){
if(time%6==0 && frame>=90){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,boss1x,boss1y-10);
	Obj_SetAngle(shot1,270-angle);
	Obj_SetSpeed(shot1,2);
	ObjShot_SetGraphic(shot1,24);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;

	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,boss2x,boss2y-10);
	Obj_SetAngle(shot1,270+angle);
	Obj_SetSpeed(shot1,2);
	ObjShot_SetGraphic(shot1,23);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle+=14;
SetCommonData("UseSpell1",20);
SetCommonData("UseSpell2",20);
}
if(time%10==0 && time>=90){ PlaySE(SEshots6); }


let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){ bullet1=erase(bullet1,i); timer1=erase(timer1,i); i--; }
	else{
		if(Obj_GetX(bullet1[i])<=minx){
		let random=rand_int(0,1);
			loop(random){
			let angle=rand(-100,100);
			CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-0.5,-1.5),-0.01*cos(angle),0.05,0.1*cos(angle),2,1,0);
			}
		Obj_Delete(bullet1[i]);
		if(soundtime==0){ PlaySE(SEmagics5); soundtime=5; }
		}
		if(Obj_GetX(bullet1[i])>=maxx){
		let random=rand_int(0,1);
			loop(random){
			let angle=rand(100,280);
			CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(-0.5,-1.5),-0.01*cos(angle),0.05,0.1*cos(angle),2,3,0);
			}
		Obj_Delete(bullet1[i]);
		if(soundtime==0){ PlaySE(SEmagics5); soundtime=5; }
		}
		if(Obj_GetY(bullet1[i])<=miny){
		let random=rand_int(0,1);
			loop(random){
			let angle=rand(0,180);
			CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),2*cos(angle),rand(0,1.5),-0.01*cos(angle),0.05,0.1*cos(angle),2,2,0);
			}
		Obj_Delete(bullet1[i]);
		if(soundtime==0){ PlaySE(SEmagics5); soundtime=5; }
		}
	timer1[i]=timer1[i]+1;
	}
i++;
}

if(soundtime>0){ soundtime--; }
if(soundtime<0){ soundtime=0; }

} //Easy

//=============================================================================================================

if(GetCommonData("Difficulty")==2){

if(time%4==0 && frame>=90){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,boss1x,boss1y-10);
	Obj_SetAngle(shot1,270-angle);
	Obj_SetSpeed(shot1,2);
	ObjShot_SetGraphic(shot1,24);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;

	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,boss2x,boss2y-10);
	Obj_SetAngle(shot1,270+angle);
	Obj_SetSpeed(shot1,2);
	ObjShot_SetGraphic(shot1,23);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle-=10;
SetCommonData("UseSpell1",20);
SetCommonData("UseSpell2",20);
}
if(time%8==0 && time>=90){ PlaySE(SEshots6); }


let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){ bullet1=erase(bullet1,i); timer1=erase(timer1,i); i--; }
	else{
		if(Obj_GetX(bullet1[i])<=minx){
		let random=rand_int(0,1);
			loop(random){
			let angle=rand(-100,100);
			CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),1.8*cos(angle),rand(-0.5,-1.5),-0.01*cos(angle),0.05,0.1*cos(angle),2,1,0);
			}
		Obj_Delete(bullet1[i]);
		if(soundtime==0){ PlaySE(SEmagics5); soundtime=5; }
		}
		if(Obj_GetX(bullet1[i])>=maxx){
		let random=rand_int(0,1);
			loop(random){
			let angle=rand(100,280);
			CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),1.8*cos(angle),rand(-0.5,-1.5),-0.01*cos(angle),0.05,0.1*cos(angle),2,3,0);
			}
		Obj_Delete(bullet1[i]);
		if(soundtime==0){ PlaySE(SEmagics5); soundtime=5; }
		}
		if(Obj_GetY(bullet1[i])<=miny){
		let random=rand_int(0,1);
			loop(random){
			let angle=rand(0,180);
			CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),1.8*cos(angle),rand(0,1.5),-0.01*cos(angle),0.05,0.1*cos(angle),2,2,0);
			}
		Obj_Delete(bullet1[i]);
		if(soundtime==0){ PlaySE(SEmagics5); soundtime=5; }
		}
		if(Obj_GetY(bullet1[i])>=maxy){
		let random=rand_int(0,1);
			loop(random){
			let angle=rand(180,360);
			CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),1.8*cos(angle),rand(-1.5,-3),-0.01*cos(angle),0.05,0.1*cos(angle),2,12,0);
			}
		Obj_Delete(bullet1[i]);
		if(soundtime==0){ PlaySE(SEmagics5); soundtime=5; }
		}
	timer1[i]=timer1[i]+1;
	}
i++;
}

if(soundtime>0){ soundtime--; }
if(soundtime<0){ soundtime=0; }

} //Normal

//=============================================================================================================

if(GetCommonData("Difficulty")==3){
if(time%4==0 && frame>=90){
	loop(2){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,boss1x,boss1y-10);
	Obj_SetAngle(shot1,270-angle);
	Obj_SetSpeed(shot1,2);
	ObjShot_SetGraphic(shot1,24);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;

	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,boss2x,boss2y-10);
	Obj_SetAngle(shot1,270+angle);
	Obj_SetSpeed(shot1,2);
	ObjShot_SetGraphic(shot1,23);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle+=180;
	}
angle+=6;
SetCommonData("UseSpell1",20);
SetCommonData("UseSpell2",20);
}
if(time%6==0 && time>=90){ PlaySE(SEshots6); }


let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){ bullet1=erase(bullet1,i); timer1=erase(timer1,i); i--; }
	else{
		if(Obj_GetX(bullet1[i])<=minx){
		let random=rand_int(0,1);
			loop(random){
			let angle=rand(-100,100);
			CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),1.6*cos(angle),rand(-0.5,-1.5),-0.01*cos(angle),0.05,0.1*cos(angle),2,1,0);
			}
		Obj_Delete(bullet1[i]);
		if(soundtime==0){ PlaySE(SEmagics5); soundtime=5; }
		}
		if(Obj_GetX(bullet1[i])>=maxx){
		let random=rand_int(0,1);
			loop(random){
			let angle=rand(100,280);
			CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),1.6*cos(angle),rand(-0.5,-1.5),-0.01*cos(angle),0.05,0.1*cos(angle),2,3,0);
			}
		Obj_Delete(bullet1[i]);
		if(soundtime==0){ PlaySE(SEmagics5); soundtime=5; }
		}
		if(Obj_GetY(bullet1[i])<=miny){
		let random=rand_int(0,1);
			loop(random){
			let angle=rand(0,180);
			CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),1.6*cos(angle),rand(0,1.5),-0.01*cos(angle),0.05,0.1*cos(angle),2,2,0);
			}
		Obj_Delete(bullet1[i]);
		if(soundtime==0){ PlaySE(SEmagics5); soundtime=5; }
		}
		if(Obj_GetY(bullet1[i])>=maxy){
		let random=rand_int(0,1);
			loop(random){
			let angle=rand(180,360);
			CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),1.6*cos(angle),rand(-1.5,-3),-0.01*cos(angle),0.05,0.1*cos(angle),2,12,0);
			}
		Obj_Delete(bullet1[i]);
		if(soundtime==0){ PlaySE(SEmagics5); soundtime=5; }
		}
	timer1[i]=timer1[i]+1;
	}
i++;
}

if(soundtime>0){ soundtime--; }
if(soundtime<0){ soundtime=0; }

} //Hard

//=============================================================================================================

if(GetCommonData("Difficulty")==4){

if(time%3==0 && frame>=90){
	loop(2){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,boss1x,boss1y-10);
	Obj_SetAngle(shot1,270-angle);
	Obj_SetSpeed(shot1,2.5);
	ObjShot_SetGraphic(shot1,24);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;

	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,boss2x,boss2y-10);
	Obj_SetAngle(shot1,270+angle);
	Obj_SetSpeed(shot1,2.5);
	ObjShot_SetGraphic(shot1,23);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle+=180;
	}
angle-=8;
SetCommonData("UseSpell1",20);
SetCommonData("UseSpell2",20);
}
if(time%5==0 && time>=90){ PlaySE(SEshots6); }


let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){ bullet1=erase(bullet1,i); timer1=erase(timer1,i); i--; }
	else{
		if(Obj_GetX(bullet1[i])<=minx){
		let random=rand_int(0,1);
			loop(random){
			let angle=rand(-100,100);
			CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),1.4*cos(angle),rand(-0.5,-1.5),-0.01*cos(angle),0.05,0.1*cos(angle),2,1,0);
			}
		Obj_Delete(bullet1[i]);
		if(soundtime==0){ PlaySE(SEmagics5); soundtime=5; }
		}
		if(Obj_GetX(bullet1[i])>=maxx){
		let random=rand_int(0,1);
			loop(random){
			let angle=rand(100,280);
			CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),1.4*cos(angle),rand(-0.5,-1.5),-0.01*cos(angle),0.05,0.1*cos(angle),2,3,0);
			}
		Obj_Delete(bullet1[i]);
		if(soundtime==0){ PlaySE(SEmagics5); soundtime=5; }
		}
		if(Obj_GetY(bullet1[i])<=miny){
		let random=rand_int(0,1);
			loop(random){
			let angle=rand(0,180);
			CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),1.4*cos(angle),rand(0,1.5),-0.01*cos(angle),0.05,0.1*cos(angle),2,2,0);
			}
		Obj_Delete(bullet1[i]);
		if(soundtime==0){ PlaySE(SEmagics5); soundtime=5; }
		}
		if(Obj_GetY(bullet1[i])>=maxy){
		let random=rand_int(0,1);
			loop(random){
			let angle=rand(180,360);
			CreateShot12(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),1.4*cos(angle),rand(-1.5,-3),-0.01*cos(angle),0.05,0.1*cos(angle),2,12,0);
			}
		Obj_Delete(bullet1[i]);
		if(soundtime==0){ PlaySE(SEmagics5); soundtime=5; }
		}
	timer1[i]=timer1[i]+1;
	}
i++;
}

if(soundtime>0){ soundtime--; }
if(soundtime<0){ soundtime=0; }

} //Lunatic


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }

#include_function "script/Functions/HealthBar.txt";
}

@BackGround{
}

@DrawLoop{
}

@Finalize{
//	SetCommonData("Conversation",1);
}

}